use std::fs::File;
use lettre::{Message, SmtpTransport, Transport};
use lettre::transport::smtp::Error;
use lettre::message::{header, IntoBody, Mailbox};
use lettre::message::header::ContentType;
use lettre::transport::smtp::authentication::Credentials;
use lettre::transport::smtp::response::Response;
use lettre::transport::smtp::SmtpTransportBuilder;

pub mod qq_email;

/**
	确认要转达的消息类型,
	别问我为什么只有Text和Html,因为它不让我自定义Content-Type头信息,比如下面代码会报错
```rust
	const APPLICATION_OCTET_STREAM: ContentType = header::ContentType(mime::APPLICATION_OCTET_STREAM);
```
 */
pub enum EmailBody<T:IntoBody> {
	Text(T),
	Html(T),
	Null
}

trait EmailMessage {
	
	fn get_credentials() -> Credentials;
	
	fn get_smtp_servers() -> &'static str;
	
	///[`None`]:则使用默认名或者无名 , [`Some(v)`]:使用v作为名字
	fn get_mailbox(s:Option<String>) -> Mailbox ;
	
	fn get_smtp_transport() -> SmtpTransport {
		SmtpTransport::relay(Self::get_smtp_servers())
			.expect("可能是邮件配置出现问题")
			.credentials(Self::get_credentials()).build()
	}
}
pub trait EmailBuilder<S:Into<String>,T:IntoBody> : EmailMessage {
	///设置发件人name
	fn from_name(self,s:String) -> Self;
	///设置收件人
	fn to(self,to:Vec<Mailbox>) -> Self;
	///设置抄送
	fn cc( self,cc:Vec<Mailbox>) -> Self;
	///设置密件抄送
	fn bcc( self,bcc:Vec<Mailbox>) -> Self;
	///设置主题
	fn subject( self,subject:S)->Self;
	///设置body
	fn body( self,body:EmailBody<T>) -> Self;
}
pub trait EmailSend : EmailMessage {
	/// 发送将会消耗自身 , 这意味着你只能发送一次
	/// 我认为邮件没有重复发送的必要,第二用clone()消耗没必要的资源
	fn send(self)->Result<Response,Error>;
}







